<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<%@ include file="/common/plateform/include/common-base.jsp"%>
		<title>角色管理</title> <!-- Tell the browser to be responsive to screen width -->
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
			name="viewport">
</head>
<body class="hold-transition ${sysColor} sidebar-mini">
	<div class="wrapper">
		<!-- top start -->
		<%@include file="/common/plateform/top.jsp"%>
		<!-- top end -->
		<!-- left start -->
		<%@include file="/common/plateform/left.jsp"%>
		<!-- left end-->
		<div class="content-wrapper">
		  <!-- - 
			<br />
			<ol class="breadcrumb bgblue">
				<li><span class="label label-danger font14">权限管理 /角色管理</span></li>
			</ol>-->
			<!-- Main start -->
			<section class="content">
			<div class="row">
				<div class="col-xs-12">
					<div class="box box-success">
					   <div class="box-header with-border">
                 <h3 class="box-title"><i class="fa fa-user"></i>  角色管理　　　
					 <!--
					<button class="btn btn-success" type="button" onclick="toAdd();">增加</button>
				        <button class="btn btn-danger" type="button" onclick="del();">删除</button>
				        <button class="btn btn-info" type="button" onclick="toEdit();">修改</button>-->
				        <button type="button" class="btn btn-info" onclick="popRoleActs();">权限</button>
				        <button class="btn btn-warning" type="button" onclick="refresh();">刷新</button>
                 </h3>
                 <div class="box-tools pull-right">
	                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
	                </button>
	                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
                 </div>
              </div>
						<!-- /.box-header -->
						<div class="box-body">
							<table id="example" class="table table-bordered ">
								<thead>
									<tr>
										<th>角色名称</th>
										<th>角色标识</th>
										<th>所属机构</th>
										<th>创建人</th>
										<th>创建时间</th>
									</tr>
								</thead>
								<tbody id="myList"></tbody>
							</table>
							<center>
								<ul id="pageList"></ul>
							</center>
						</div>
					</div>
				</div>
			</div>
			</section>
			<!-- Main end -->
			
			
	<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						<h4 class="modal-title"><font color="red">角色信息</font>&nbsp;</h4>
					</div>
					<div class="modal-body">
						<form class="form-horizontal" role="form" id="orgForm">
							<input type="hidden" name="formToken" id="formToken" value="${formToken}">
							 <input type="hidden" name="doCode" value="roleSave" /> 
							 <input type="hidden" name="roleId" id="roleId" data-name="roleId" value="">
							 <input type="hidden" name="orgParam" id="orgParam" value=""/>
		                     <input type="hidden" name="delStatus" id="delStatus" data-name="delStatus" value=""/>
									<div class="box-body" id="orgFormData">
										<div class="form-group">
											<label for="inputOrgCname" class="col-sm-2 control-label">角色名称</label>
											<div class="col-sm-8">
												<input type="text" class="form-control" id="roleCname"
													name="roleCname" data-name="roleCname" required placeholder="必填项">
											</div>
										</div>

										<div class="form-group">
											<label class="col-sm-2 control-label">角色标识</label>
											<div class="col-sm-8">
												<input type="text" class="form-control" id="roleEname"
													name="roleEname"  data-name="roleEname" required placeholder="必填项">
											</div>
										</div>

									<div class="box-footer">
										<button type="button" class="btn btn-primary pull-left"
											onclick="cannel('my_modal');">取消</button>
										<button type="button" class="btn btn-primary pull-right"
											onclick="save('orgForm');">提 交</button>
									</div>
						    </div>
						</form>
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
		</div>		
			
	<!-- 角色权限设置 -->
<div class="modal fade" id="role_acts_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog" style="width:1000px">
				<div class="modal-content">
					<div class="modal-body" id="roleActsDiv"> 
					</div>
				</div>
				<!-- /.modal-content -->
			</div>
</div>		
			
<script type="text/template" id="dataList">
	  		<? for ( var i = 0; i < rows.length; i++) {?>
				<tr id=<?=rows[i].roleId?>><th style="display:none"><?=rows[i].roleId?></th>
					<td><?=rows[i].roleCname?></td>
                    <td><?=rows[i].roleEname?></td>
					<td><?=rows[i].roleRemark?></td>
					<td><?=rows[i].createUser?></td>
					<td><?=getFormatDateByLong(rows[i].createTime,'yyyy-MM-dd hh:mm:ss')?></td>
				</tr>
     		<?}?>
</script>			
			
<script>
	var clickMenu = 'role-list';
	var id;
	var ename;
	var cname;
	$(function() {
		getTableData();
		$('#example tbody').on('click', 'tr', function(e) {
			if ($(this).hasClass('selected')) {
			} else {
				$('tr.selected').removeClass('selected');
				$(this).addClass('selected');
			}
			id = $('tr.selected th').eq(0).html();
		});
	});

	//设置模态框隐藏事件钩子  
	$('#my_modal').on('hide.bs.modal', function(e) {
		cleanData('orgFormData');
	});

	//设置模态框隐藏事件钩子  
	$('#my_modal').on('show.bs.modal',
		function(e) {
			$.ajax({
				type : 'get',
				url : '${ctx}/sendPage/token?token=true&date='
							+ new Date().getTime(),
				dataType : 'text',
				success : function(myData) {
					$('#formToken').val(myData);
				}
			});
	});

	function cleanData(id) {
		$(':input', '#' + id).not(':button, :submit, :reset, :hidden,:radio')
				.val('')
				//.removeAttr('checked')  
				.removeAttr('selected');
	}

	function getTableData() {
		deleteAllRow();
		$.ajax({type:'get',url : common_list_url+"roleList",dataType:'json',
			data:{doCode:'roleList'}+ getCurrentPage(common_list_url + "?doCode=roleList", 10),
			success : function(myData) {
				var data = baidu.template('dataList', myData);
				$("#myList").html(data);
				var option = {
					ele : $("#pageList")[0],
					total : myData.total,
					fn : getTableData,
					url : common_list_url + "?" + $('#searchFrom').serialize()
				}
				generatePages(option);
			}
		});
	}

	function toAdd(val) {
		if (val == 'child') {
			if (id == "undefined" || id == "" || id == null) {
				layer.alert('请先选中一条数据！', {
					skin : 'layui-layer-lan',
					closeBtn : 0
				});
				return;
			} else {
				$("#parentId").val(id);
			}
		} else {
			$("#channelId").val("");
		}
		$('#my_modal').modal('show');
	}

	function del() {
		if (id == "undefined" || id==null || id=="") {
			alert("请先选中一条数据！");
			return;
		} else {
			var index_submit = layer.confirm('您确定要删除信息吗？', {btn: ['Yes','No'],closeBtn: 0,offset: '220px'}
			, function(){
				layer.close(index_submit);
				$.ajax({type : 'post',url : common_submit_url,dataType : 'json',
					data : {'roleId' : id,'doCode' : 'roleDel'},
					success : function(myData) {
						if (myData.flag == 'T') {refresh();}
						layer.alert(myData.msg, {skin : 'layui-layer-molv',closeBtn : 0});
					}
				});
			});
			
		}

	}

	function save(formId) {
		if (!$("#" + formId)[0].checkValidity()) {
			alert("请先完善必输项和必选项！");
			return;
		}
		$.ajax({
			type : 'post',
			url : common_submit_url,
			data : $("#" + formId).serialize(),
			dataType : 'json',
			success : function(myData) {
				//console.log(myData);
				if (myData.flag == 'T') {
					layer.alert('操作成功！', {
						skin : 'layui-layer-molv',
						closeBtn : 0
					});
					refresh();
				} else {
					alert(myData.msg);
				}
				$('#my_modal').modal('hide');
			}
		});
	}

	function cannel(id) {
		$('#' + id).modal('hide');
	}
	function deleteAllRow() {
		var tb = document.getElementById('example');
		if (tb) {
			var rowNum = tb.rows.length;
			for (i = 1; i < rowNum; i++) {
				tb.deleteRow(i);
				rowNum = rowNum - 1;
				i = i - 1;
			}
		}
	}

	function refresh() {
		//window.location.reload();
		getTableData();
	}
	
	function toEdit(){
		if(id=="undefined" || id =="" || id == null){
			alert("请先选中一条数据！");
			return;
		}else{
			$.ajax({ type:'get', url:common_info_url,dataType:'json',
			    data:{'roleId':id,'doCode':'roleInfo'},
			    success: function(myData){
			    	 //console.log(myData);
			    	 FormUtil.loadView("", myData);
					 $('#my_modal').modal('show');
			  	}
			});	
		}
	}
	function popRoleActs(){
		if(id=="undefined" || id =="" || id == null){
			alert("请先选中一条数据！");
			return;
		}else{
			$("#roleActsDiv").load("${ctx}/template/uct/role-acts.html",function(){getRoleListData(id,"0");
			$('#role_acts_modal').modal('show');
			$('#role-actsTable tbody').on('click','tr', function (e) {
			     if ( $(this).hasClass('selected') ) {
			        }  else {
			            $('tr.selected').removeClass('selected');
			            $(this).addClass('selected');
			        }
			     deptNum = $('tr.selected th').eq(0).html();
			  });
			});
		}
	}
</script>			
			
			
		</div>
		<!-- /.content-wrapper -->
</div>
		<!-- foot start -->
		<%@include file="/common/plateform/foot.jsp"%>
		<!-- foot start -->
		
		
</body>



</html>
